home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_65 / monitor.cpp < prev    next >
C/C++ Source or Header  |  1995-01-01  |  1KB  |  46 lines

  1. // Monitor.cpp
  2.  
  3. // Displays a real-time bar graph of the Sound Blaster recording input
  4. // This demonstrates the SoundDevice function monitor_input()
  5.  
  6. // Written by Christopher M. Box, modified from play_rec.cpp
  7.  
  8. // Usage: monitor [sample rate]
  9.  
  10. #define DMA_BUF_SIZE 32000U
  11. #define ALLOCATE ((2*DMA_BUF_SIZE) + 65536L)
  12.  
  13. #include <conio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18.  
  19. #include "sndclass.h"
  20.  
  21. int main(int argc, char **argv) {
  22.     unsigned sr=10000;         // Default sample rate
  23.  
  24.     if (argc > 1) sr = atoi(argv[1]);
  25.  
  26.     SoundDevice *sdev;
  27.     sdev = new SbDevice;
  28.     if (! sdev -> install_ok()) exit(1);
  29.  
  30. // Obtain an aligned 64K memory buffer for the DMA functions
  31.     byte far *raw = (byte far *) farmalloc(ALLOCATE);
  32.     if (! raw) {
  33.         cprintf("Not enough memory available - an extra %uK needed.\r\n",
  34.             ((unsigned int)(ALLOCATE-farcoreleft()))/1024+1);
  35.         exit(1);
  36.     }
  37.     long physical = ((long)FP_OFF(raw)) + (((long)FP_SEG(raw)) << 4);
  38.     long aligned_physical = (physical+0x0FFFFL) & 0xF0000L;
  39.     byte far *buf = (byte far *)
  40.         MK_FP((unsigned )((aligned_physical >> 4) & 0xFFFF),0);
  41.  
  42.     sdev -> set_rate(sr,RECORD);
  43.     sdev -> monitor_input(buf,1000);
  44.     farfree(raw);
  45.     return 0;
  46. }